package com.devunion.reader.server.mediator;

import com.devunion.bogdan.model.project.Annotation;
import com.devunion.bogdan.model.project.Page;
import com.devunion.reader.client.to.AnnotationTo;
import com.devunion.reader.client.to.ProjectTreeTo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Timoshenko Alexander 28.05.2009 : 11:19:51
 */
public class PageMediator implements IMediator<Page, ProjectTreeTo> {
    private AnnotationMediator annotationMediator;

    public void setAnnotationMediator(AnnotationMediator annotationMediator) {
        this.annotationMediator = annotationMediator;
    }

    public ProjectTreeTo copyFromEntity(Page anEntity) {
        ProjectTreeTo theTo = new ProjectTreeTo();
        theTo.setId(anEntity.getPageId());
        theTo.setRelativePath(anEntity.getRelativePath());
        theTo.setPageNumber(anEntity.getPageNumber());

        List<AnnotationTo> theAnnotationToList = new ArrayList<AnnotationTo>();
        if (anEntity.getAnnotations() != null) {
            for (Annotation anEach : anEntity.getAnnotations()) {
                theAnnotationToList.add(annotationMediator.copyFromEntity(anEach));
            }
        }
        theTo.setAnnotations(theAnnotationToList);
        return theTo;
    }
}
